package com.course.coursedesign2022.service;

import com.course.coursedesign2022.mapper.UserMapper;
import com.course.coursedesign2022.pojo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BloodSugar {
    @Autowired
    UserMapper userMapper;

    public UserInfo bloodSugar(Integer id){
        UserInfo userInfo = userMapper.getUserInfoById(id);
        Integer growscore = userInfo.getGrowscore();
        Integer scoretotal = userInfo.getScoretotal();
        int bloodNum = userInfo.getBloodNum();
        if(bloodNum < 3){
            System.out.println("血糖次数小于3，无法积分");
        }else if(bloodNum == 3){
            userInfo.setGrowscore(growscore+1);
            userInfo.setScoretotal(scoretotal+1);
            System.out.println("血糖积分+1");
        }else{
            System.out.println("已获得血糖积分，无法再次获得");
        }
        userInfo.setBloodNum(bloodNum+1);
        userMapper.updateUserInfo(userInfo);
        return userInfo;
    }
}
